<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>登录页面</title>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<style type="text/css">
h1 {
	color: #009CFF
}
;
</style>
</head>
<body>
	<img src="../images/baidu.png">
	<center>
		<form action="login" method="post" id="form1">
			<h1>用户登录</h1>
			<p>
				用户名： <input type="text" name="uname" id="uname" onblur="checkName()">
				<font class="fot"></font>
			</p>
			<p>
				密码： <input type="password" name="upwd" id="upwd" onblur="checkPwd()">
				<font class="fot1"></font>
			</p>
			<p>
				<a href="index"><input type="button" value="返回首页" style="background-color: #9AD2D2" /></a>
				<input type="button" value="找回密码" style="background-color: #9AD2D2" />
				<input type="submit" value="登录" style="background-color: #9AD2D2"/>
				<a href="toregister"><input type="button" value="新用户注册" style="background-color: #9AD2D2"/></a> 
				<a href="#">收藏本站</a>
			</p>
		</form>
	</center>
</body>
<script type="text/javascript">
	$(function() {
	});
	$("#form1").submit(function() {
		if ($("#uname").val() == null || $("#uname").val() == "") {
			alert("用户名不能为空");
		} else {
			if ($("#upwd").val() == null || $("#upwd").val() == "") {
				alert("密码不能为空");
			}
		}
	});

	function checkName() {
		var name = $("#uname").val();
		if (""!= name) {
			$.ajax({
				type : "POST",
				url : "checkname",
				data : "name=" + name,
				dataType : "json",
				success : function(data) {
					if (data.state == "0") {
						$(".fot").text("用户名不存在");
					}else {
						$(".fot").text("");
					}
				},
				error : function() {
					alert("error");
				}
			});
		}
	}
	function checkPwd() {
		var name = $("#uname").val();
		var pwd = $("#upwd").val();
		if (""!= pwd) {
			$.ajax({
				type : "POST",
				url : "checkpwd",
				data : "name="+name+"&pwd="+pwd, 
				dataType : "json",
				success : function(data) {
					if (data.num == "0") {
						$(".fot1").text("用户名与密码不一致");
					}else {
						$(".fot1").text("");
					}
				},
				error : function() {
					alert("error");
				}
			});
		}
	}
</script>
</html>